package com.eboss.sbs.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.eboss.sbs.R;
import com.eboss.sbs.activity.base.BaseActivity;
import com.mytools.tool.utils.DataCleanManager;
import com.mytools.tool.utils.SystemUtil;
import com.mytools.tool.views.MyDialog;

import java.text.DecimalFormat;

public class SettingActivity extends BaseActivity {
	
	private double currentCacheSize = 0.0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mActivity = this;
		setContentView(R.layout.activity_setting);
		super.onCreate(savedInstanceState);
		initView();
	}

	private void initView(){
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "设置");
		
		currentCacheSize = DataCleanManager.getCacheSize(mActivity);
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);
		findViewById(R.id.layout_modify_password).setOnClickListener(this);
		findViewById(R.id.layout_clean_cache).setOnClickListener(this);
		
		setTvText(R.id.tv_version_name, SystemUtil.getVerName(mActivity));
		
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				finish();
				break;
			case R.id.layout_modify_password:
				startActivity(new Intent(mActivity, PasswordModifyActivity.class));
				break;
			case R.id.layout_clean_cache:
				MyDialog.Builder builder = new MyDialog.Builder(this);
				builder.setTitle("提示");
				builder.setMessage("确定要清除缓存，请谨慎操作！");
				builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						cleanCacheData();
					}
				});
				builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
					}
				});
				builder.create().show();
				break;
			default: break;
		}
		super.onClick(v);
	}
	
	private void cleanCacheData(){
		DataCleanManager.deleteCache(mActivity);
		DecimalFormat df = new DecimalFormat("######0.00"); 
		toast("成功清楚缓存"+df.format(currentCacheSize)+"M");
		currentCacheSize = 0.0;
	}
	
}
